<template>
	<view class="fui-wrap">
		<block v-if="platform=='PC'">
			<view class="plate_number_box">
				<fui-input v-model="plate_number" :inputBorder="true" placeholder="请输入车牌号"></fui-input>
				<fui-button :disabledButton="disabledButton" :margin="['48rpx','0','24rpx']" @click="clickConfirm" text="确认车牌号" type="success" bold></fui-button>
			</view>
			<pcfooter></pcfooter>
		</block>
		<block v-else>
			<plateNumber v-if="parking" ref="platenumber" :value="parking.plate_begin" @confirm="confirmPlate" @cancel="cancelPlate"></plateNumber>
		</block>
		<fui-modal :buttons="[{text:'确定'}]" :show="show" :descr="descr" maskClosable @click="clickButton" @cancel="show=false;"></fui-modal>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration} from '@/utils/util.js';
	import plateNumber from '@/components/common/plate.vue';
	import pcfooter from '@/components/common/pcfooter.vue';
	export default {
		components:{
			plateNumber:plateNumber,
			pcfooter:pcfooter
		},
		data() {
			return {
				parking:'',
				plate_number:'',
				disabledButton:false,
				show:false,
				descr:'',
				platform:''
			}
		},
		onLoad(e) {
			this.qrcode_id=e.qrcode_id;
			this.$platform();
			this.getParking();
		},
		methods: {
			...methods,
			getParking:function(){
				this.$get('merchant/index/info').then(res=>{
					this.parking=res.parking;
				});
			},
			confirmPlate:function(plate_number){
				this.$post('merchant/index/search',{plate_number:plate_number},true,false).then(res=>{
					if(this.platform!='PC'){
						this.$refs.platenumber.hideKeyboard();
					}
					this.descr='入场时间：'+res.entry_time_txt+'\n停车时长：'+formatDuration(res.records_time,'minutes')
					this.show=true;
				}).catch(e=>{
					if(this.platform!='PC'){
						this.$refs.platenumber.hideKeyboard();
					}
					this.descr=e.msg;
					this.show=true;
				});
			},
			clickConfirm:function(){
				this.confirmPlate(this.plate_number);
			},
			cancelPlate:function(){
				this.$navigateBack();
			},
			clickButton:function(){
				if(this.platform!='PC'){
					this.$refs.platenumber.showKeyboard();
					this.$refs.platenumber.init();
				}
				this.plate_number='';
				this.show=false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fui-wrap {
		background-color: #fff;
		padding-bottom: 40rpx;
	}
	.plate_number_box{
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 300rpx;
	}
</style>